package com.oocl.exception.handler;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.exception.ExceptionManage;

/**
 * Servlet Filter implementation class ExceptionFilter
 */
public class ExceptionFilter implements Filter {

   
    public ExceptionFilter() {
    }

	
	public void destroy() {
		// TODO Auto-generated method stub
	}

	
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletResponse resp = (HttpServletResponse)response;
		HttpServletRequest req = (HttpServletRequest)request;
		try{
			chain.doFilter(request, response);
		}catch(Exception e){
			ExceptionManage handler =  new ExceptionManage(e);
			handler.setResponse(resp);
			handler.setRequest(req);
			handler.handler();
		}
	}

	
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
